#pragma once

extern "C" {
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/imgutils.h>
#include <libavutil/timestamp.h>
// #include <libswscale/swscale.h>

#include "hb_comm_venc.h"
#include "hb_comm_vdec.h"
#include "hb_venc.h"
#include "hb_vdec.h"
#include "hb_vio_interface.h"
#include "hb_sys.h"
#include "ion.h"
}

#include "stream/horizon/base_osd.h"
#include "camera/hikbase.h"
#include "stream/total_struct.h"
#include "stream/base_pusher.h"


namespace stream {

#define STREAM_FRAME_SIZE 2097152

class HBStreamPusher: public BasePusher
{
public:
  HBStreamPusher(StreamPusherInfo* spifo, LogInfo* log_info);
  ~HBStreamPusher();

public:
  static int global_init();
  static int global_release();

  int init_params();
  int start_push();
  int stop_push();
  int add_frame(stream::ImageBlob& buffer);

private:
  int start_push_imp();
  int start_push_listener();

  int init_pusher_params();
  int init_venc_params();
  void release_ffmpeg();
  void release_encoder();
  int venc_ChnAttr_init(VENC_CHN_ATTR_S *pVencChnAttr);
  int venc_setRcParam(int chn, int bitRate, VENC_CHN_ATTR_S *pVencChnAttr);

public: 


private:
  std::mutex queue_lock;
  std::queue<stream::ImageBlob> queue_data;

  AVFormatContext *pfmt_ctx = nullptr;
  AVCodec *out_codec = nullptr;
  AVStream *out_stream = nullptr;
  AVCodecContext *out_codec_ctx = nullptr;

  // init module
  void *encoder = nullptr;
  void *vps = nullptr;


};


}   // namespace camera
